/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.lottery.game.core.modules.service.app;

import com.alibaba.fastjson.JSONObject;
import com.lottery.game.common.constants.GameConstants;
import com.lottery.game.core.modules.entity.user.UpAndDownReport;
import com.lottery.game.core.modules.mapper.UpAndDownReportDao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;

/**
 * 上下分报表Service
 * @author qq
 * @version 2018-05-25
 */
@Slf4j
@Service
public class UpAndDownReportService {

	@Autowired
	private UpAndDownReportDao upAndDownReportDao;

	@Autowired
	private WebSocketService webSocketService;

	public UpAndDownReport get(String id) {
		return this.upAndDownReportDao.get(id);
	}

	public List<UpAndDownReport> findListtotal(UpAndDownReport upAndDownReport) {
		return this.upAndDownReportDao.findListtotal(upAndDownReport);
	}

	public List<UpAndDownReport> findList(UpAndDownReport upAndDownReport) {
		return this.upAndDownReportDao.findList(upAndDownReport);
	}


	@Transactional
	public void save(UpAndDownReport upAndDownReport) {
		if (upAndDownReport.getId() == null) {
			upAndDownReport.setId(UUID.randomUUID().toString().replace("-", ""));
			this.upAndDownReportDao.insert(upAndDownReport);
		} else {
			this.upAndDownReportDao.update(upAndDownReport);
		}

	}

//	@Transactional(readOnly = false)
	public void delete(UpAndDownReport upAndDownReport) {
		this.upAndDownReportDao.delete(upAndDownReport);
	}

	/**
	 * 上下分消息申请结果的反馈 - WS推送
	 *
	 * @param userId
	 */
	public void upAndDownFeedbaakPublish(String userId,Boolean result ,BigDecimal balance) {
		log.info("上下分消息申请结果的反馈 - WS推送");
		Map<String, Object> contentMap = new HashMap<>(3);
		contentMap.put("result",result);
		contentMap.put("balance",balance);
		contentMap.put("type", GameConstants.SYS_MSG_SXFEN);

		String sendMsg = JSONObject.toJSONString(contentMap);
		webSocketService.sendToTheUser(sendMsg, userId, GameConstants.SYS_MSG_SXFEN,null);
	}
}
